// exports.oldModule = ()=>{
var basePath = 'http://localhost:8080/';
var thisPath = 'http://localhost:9000/#/';
var agentId=56131;
var serverError = "服务器异常";


function getFunctionPermissionVue (params) {
  var functionPermissions;
  $.ajax({
    type : 'post',
    url : basePath + 'getFunctionPermissionVue',
    data : JSON.stringify(params),
    dataType : 'json',
    contentType:'application/json;charset=utf-8',
    async : false,
    success : function(data){
      if (!data || data.errorCode != 0) {
        functionPermissions = false;
      }
      functionPermissions = data.data;
    },
    error : function (data) {
      functionPermissions = false;
    }
  });
  return functionPermissions;
}

function showMsg(msg){
    $(".msg").css("display","block");
    $(".msg").text(msg);
}

function validateReqStatus(data, callback) {
    if (data != null && data.errorCode == "0") {
        callback && callback();
    } else {
        var msg = data.message == undefined ? data.msg : data.message;
        IwJwUtils.Messages.error({msg:('操作失败', (msg == "" || msg == undefined) ? '操作失败' : msg)});
    }
}

$.fn.serializeJson = function () {
    var serializeObj = {};
    var array = this.serializeArray();
    $(array).each(function () {
        if (serializeObj[this.name]) {
            if ($.isArray(serializeObj[this.name])) {
                serializeObj[this.name].push(this.value);
            } else {
                serializeObj[this.name] = [serializeObj[this.name], this.value];
            }
        } else {
            serializeObj[this.name] = this.value;
        }
    });
    return serializeObj;
};

function isEmpty(str) {
    if (str == undefined) {
        return true;
    }
    if ($.trim(str) == "") {
        return true;
    }
    if (str.length == 0) {
        return true;
    }
    return false;
}

function setFocus(sel) {
    var length = sel.value.length;
    myFocus(sel, length, length);
}

function myFocus(sel, start, end) {
    if (sel.setSelectionRange) {
        $(sel).focus();
        sel.setSelectionRange(start, end);
    } else if (sel.createTextRange) {
        var range = sel.createTextRange();
        $(sel).focus();
        range.collapse(false);
        range.moveEnd('character', end);
        range.moveStart('character', start);
        range.select();
    } else {
        $(sel).focus();
    }
}

function fnEval(data) {
    return eval('(' + data + ')');
}
//
//function stop() {
//    return false;
//}
//document.oncontextmenu = stop;


function formateDate(dd) {
    if (!dd) {
        dd = new Date();
    }
    var zr = function (n) {
        return n < 10 ? '0' + n : n;
    }
    return (dd.getFullYear() + '-' + zr(dd.getMonth() + 1) + '-' + zr(dd.getDate()) + ' ' + zr(dd.getHours()) + ':' + zr(dd.getMinutes()) + ':' + zr(dd.getSeconds()));
}

function formatterDate(curDate) {
    var y = curDate.getFullYear();
    var m = curDate.getMonth() + 1;
    var d = curDate.getDate();
    return y + '-' + m + '-' + d;
}

function GetTimeByTimeStr(dateStr) {
    var timeArr = dateStr.split(" ");
    var d = timeArr[0].split("-");
    var t = timeArr[1].split(":");
    return new Date(d[0], (d[1] - 1), d[2], t[0], t[1], t[2]);
}
function GetTimeByTimeStr2(dateStr) {
    var timeArr = dateStr.split(" ");
    var d = timeArr[0].split("-");
    return new Date(d[0], (d[1] - 1), d[2]);
}


function layer_msg_suc(msg) {
    layer.msg(msg, {icon: 1});
}

function layer_msg_fail(msg) {
    layer.msg(msg, {icon: 5});
}

//金额格式化
function fmoney(s, n) {
    n = n > 0 && n <= 20 ? n : 2;
    s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
    var l = s.split(".")[0].split("").reverse(),
        r = s.split(".")[1];
    t = "";
    for (i = 0; i < l.length; i++) {
        t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
    }
    return t.split("").reverse().join("") + "." + r;
}

//金额反格式化
function rmoney(s) {
    return parseFloat(String(s).replace(/[^\d\.-]/g, ""));
}

//限制输入只能为数字
function checkNum(e,scale) {
    var c = $(e);
    var val = c.val();

    var d = val.split(".");
    if(d.length>1 && scale!=0){
        var g = d[0];
        var f=d[1];
        f=g.replace(/[^\d]/g, '') + "." +f.substr(0,scale).replace(/[^\d]/g, '');
        $(e).val(f);
        return f;
    }
    val = val.replace(/[^\d]/g, '');
    $(e).val(val);
    return val;
}

function getFileTypeByName (name) {
  if (name) {
    let nameArr = name.split(".");
    let len = nameArr.length;
    return nameArr[len-1];
  }
  return "";
}

function checkFile (accepts,name,maxSize,size) {
  var type = getFileTypeByName(name);
  if (Array.isArray(accepts) && accepts.indexOf(type) == -1) {
    return false;
  }
  if (size > maxSize * 1024 * 1024) {
    return false;
  }
  return true;
}

function closeWindow() {
    var userAgent = navigator.userAgent;
    if (userAgent.indexOf("Firefox") != -1 || userAgent.indexOf("Presto") != -1) {
        window.location.replace("about:blank");
        window.open('', '_parent', '');
        window.close();
    } else if (navigator.userAgent.indexOf("Chrome") != -1) {
        window.location.href = "about:blank";
        window.close();
    } else {
        window.opener = null;
        window.open("", "_self");
        window.close();
    }
}

function imgLinkClick (event,obj) {
  let objClass = $(obj).attr("class");
  if (!objClass || objClass.indexOf("img-link") == -1) {
    return false;
  }
  $('.img').PreImageBox({
      container: '#viewerContainer'
  });
  event.preventDefault();
  $(obj).prev().click();
}

// }
